<?php
require $this->website['path']['action'] . '/admin/islogin.php';

$json = array('status' => 'error', 'msg' => 'error', 'data' => '');

$tit = fn_post('tit');
$upid = fn_post('upid');
$tp = fn_post('tp');
$cont = fn_post('cont');
$image = fn_post('image');

if (!$tit) {
	$json['msg'] = '参数错误,分类名称不能为空';
} elseif (!is_numeric($upid)) {
	$json['msg'] = '数据错误,上级分类不能为空';
} else {
	$id = $this->website['class']['db']
		->table('type')
		->field('upid', 'tit', 'tp', 'cont', 'image')
		->value($upid, $tit, $tp, $cont, $image)
		->insert();
	$this->website['class']['db']
		->table('type')
		->field('num')
		->value(1)
		->where("id=?", $upid)
		->increase();
	if ($id) {
		$json['status'] = 'ok';
		$json['msg'] = '分类新增成功';
		$json['data'] = $this->website['class']['db']
			->table('type')
			->where("id=?", $id)
			->one();
	} else {
		$json['msg'] = '分类新增失败';
		// $json['data'] = $this->website['class']['db']->sql;
	}
}

echo json_encode($json);